import numpy as np
import matplotlib.pyplot as plt
import datetime
# a = np.fromstring("1 2 3 4", dtype=int, sep=" ")
# print(a)
# with open('../log/log.txt', 'r') as f:
#     files = f.readlines()
# for line in files:
#     print(line)
#     cl,bl = line.split('|')
#     break
def smooth(data, weight=0.9):
    '''用于平滑曲线，类似于Tensorboard中的smooth曲线
    '''
    last = data[0]
    smoothed = []
    for point in data:
        smoothed_val = last * weight + (1 - weight) * point  # 计算平滑值
        smoothed.append(smoothed_val)
        last = smoothed_val
    return smoothed
dic={'PPO_Rewards': [112778.35549229076, 121251.71209599328, 128507.74415686238, 134660.47799356937, 139784.13683992124, 141801.82509238546, 147221.74912621768, 149499.8019626085, 150098.66394455178, 153597.21331754458, 155049.3761365279, 157492.65363610323, 158835.10500059812, 160931.1047650794, 163615.65753760398, 163687.47394255633, 164073.87448278992, 166534.87670065908, 165550.20373977246, 169719.31397100113, 165501.9993270616, 169045.82041251202, 168912.56568921337, 173493.0162587412, 171310.94584582036, 167676.9942030183, 168431.2285242536, 172230.72344599807, 173068.45626097653, 171017.39663114565, 171337.308341658, 172737.21367243756, 173952.24808247207, 172199.51049783494, 169621.09124486617, 169960.48751803764, 172352.11652236665, 173571.18196248167, 169223.61980519327, 173183.90985958473, 172565.0927960921, 175242.21381673834, 174158.30707070613, 174235.8560245311, 174609.78452380985, 173416.76839826652, 174722.6085137074, 175596.8361471857, 173026.23849206258, 173923.27222222192, 172722.8500000002, 175853.49332611717, 173975.31865079326, 175780.054365078, 175779.07752525207, 171976.543148518, 175497.80515872984, 176505.55039682507, 173653.78968254, 174437.8130952374, 170677.41507936534, 173928.33253968184, 174919.11944444303, 173778.74725829772, 173776.50198412695, 175516.1400793644, 174488.27727272734, 176264.8226190469, 175003.511147186, 175415.37637085133, 177085.8361111101, 175770.9051587287, 173733.8699134185, 177027.24603174586, 175713.8817460309, 173424.3253968249, 173628.76746031592, 177016.4466810958, 173989.24404761769, 174413.24682539707, 175549.38849206228, 178830.70238095225, 175620.769047619, 175421.28730158627, 176060.51706349154, 179588.82597402527, 175084.95873015744, 175394.45562770532, 174941.40555555423, 176742.35277777747, 177199.45912698357, 174842.40515872993, 175120.98571428432, 174505.75183982617, 173148.75198412707, 175936.47698412577, 174752.65158729994, 173013.94047618937, 176510.33134920645, 176096.87222222186], 'DQN_Rewards': [171444.28208304069, 185790.16661118617, 196801.9371450947, 206149.5515858484, 214028.00104782594, 217362.215203243, 224154.648077671, 226615.46431773299, 227719.06067800985, 232090.6692985878, 233357.72750035362, 236729.13799941863, 236650.0310013081, 239665.53048316672, 242591.24658271924, 242140.84267361378, 241395.02386212727, 243740.0287414423, 242957.84822748782, 247872.89073619203, 243259.7985195277, 248867.30490751597, 249161.944516259, 254507.93576922108, 252744.18086079566, 246887.28724663344, 248352.20275334732, 252905.79158118754, 254003.60377413844, 251453.0725885111, 250988.37835163882, 253577.5700793552, 255160.24578142946, 252691.72309522735, 249810.30073869735, 250712.17253967273, 253411.45634919478, 254784.20031745135, 248848.8635714183, 253538.80169107503, 252631.00415139308, 256983.3703968128, 254916.77555554482, 255679.08325395765, 255677.52595236973, 254300.2904761802, 256113.13873014736, 256938.1395237985, 252114.0246825294, 254083.19888887764, 252408.36999998926, 256966.4853174508, 253826.00103173588, 256518.519603165, 256687.57055554338, 252411.3949267312, 256292.07134919497, 257108.0108730063, 252172.63730157603, 254014.7888095132, 249535.91317459292, 254097.23158729175, 254001.56277776713, 253856.44396824398, 253486.30436506847, 256465.9081745918, 254877.20999998917, 256691.10976189337, 254966.12452379987, 255005.52801586306, 257182.0394444344, 255947.79134919238, 253287.11380951173, 256644.3412698281, 256340.73984126013, 254145.9158730042, 254240.88841268732, 259168.68269840206, 254796.0369047506, 254879.9430158618, 256316.65468252992, 260614.84523808496, 255985.4919047522, 255932.03206348082, 256204.93753967155, 259959.41714284522, 255287.50920633855, 253836.7023809417, 254648.29222221154, 257240.67611109946, 257689.4100793554, 254317.49134919577, 254487.3685714169, 255527.85404760815, 252421.45436506844, 255730.44936506858, 254117.43349205237, 252253.4690476074, 256713.62896824413, 255421.81888887932]}
dicqq = {'DQNu_Rewards': [115491.66135465371, 119747.29594163399, 126712.23499178613, 132600.39950536916, 139688.51811625538, 141279.03979770918, 145364.05750231436, 149486.29548213945, 151060.81034934468, 154426.01903480396, 158427.10682693627, 158997.59271548086, 162820.66485120414, 164233.27476034884, 163279.5184390128, 164405.89994044823, 168621.47738974888, 166800.982364754, 170806.97695433602, 170760.94567009836, 167880.5805828988, 173204.30735868105, 171321.23362485628, 174958.14200382825, 172868.29534632017, 176170.9203019205, 175969.48263680772, 177867.80447052952, 175830.71435231538, 175570.2424991676, 177262.09130591628, 178634.3104673104, 176626.8673520918, 179241.57507215094, 177629.12843545352, 181394.89796592348, 179132.1276515154, 179741.4285714292, 180841.3145021661, 179630.35458153024, 179175.87958153017, 179056.09743867285, 181051.78239260762, 177386.86179653654, 184232.4699855709, 178804.23780663803, 178914.05338828042, 183115.05434287968, 181586.0543290049, 180703.6716394724, 181311.83769841184, 179180.25555555613, 180419.63263403298, 180878.48809523776, 181562.17500000025, 181464.17322954812, 179250.1554806315, 181796.48650793737, 181640.36201298682, 183835.4632034631, 179075.53030303013, 181008.979761905, 179229.977922077, 183226.34834054968, 180953.08455988453, 180618.90595238094, 179092.94325396814, 180395.02658730207, 183966.11587024157, 177659.20386002894, 178177.61507936593, 181234.4821428569, 179657.54924242487, 180048.26706349137, 183732.74748584794, 185113.61269841366, 185442.015584416, 181561.56468253973, 181119.09830447298, 179853.00984848544, 179047.44278499277, 180889.9569624815, 181949.17489177568, 180045.0843073604, 180720.81111111175, 182424.3427489188, 183822.801984127, 182840.8339105338, 181084.7036435797, 186821.26547619066, 182982.7747113993, 182988.83686868692, 182271.90104617464, 180293.62128427066, 179086.55710678262, 182116.94675324604, 180159.73333333226, 180493.85039682483, 178311.50772005747, 182117.43134920736], 'DQNd_Rewards': [178357.7349802371, 184005.6510715947, 194848.8169819265, 203642.37891181046, 212518.53985575642, 215114.38755495462, 219798.72650508845, 224025.3500607015, 224336.46276855227, 228023.5018765653, 231693.53501925012, 232433.4039740528, 235868.76267264088, 237395.1044727616, 235081.2405658227, 236660.4798689792, 241469.55025744496, 237727.16120245392, 242996.84929953417, 242244.28047421112, 237786.07728237024, 244278.27618909266, 242130.21397467353, 245630.01240841963, 242703.14976189876, 246376.9246642175, 246366.56180097238, 248157.86983515936, 246277.0715750865, 245648.6334981624, 247876.20087300945, 249741.48302807842, 246483.50817459784, 249976.76515872325, 248051.0825579911, 253612.0755250221, 250575.78083332683, 250335.7428571377, 252287.29190475572, 250072.78007936108, 249685.73507935996, 250446.31436507477, 252727.62126373258, 248532.09595237486, 255620.83396824883, 249691.52317459838, 249228.61745420858, 254515.91955432817, 252275.6195238022, 251079.47760683292, 251901.3429365029, 249855.062222217, 250669.99179486724, 251729.9738095187, 251879.08499999516, 252356.58110500322, 249452.9420573836, 252166.27031745386, 252525.99642856471, 255575.81904761388, 249420.4666666617, 251881.85547618504, 250392.55142856584, 255244.0663492011, 251423.68603174048, 251761.2930952317, 249643.97515872674, 251094.9584920585, 255458.95491452498, 247689.64849205985, 248015.85317459973, 252029.86071428112, 250330.80833332767, 250700.0875396778, 254559.94446886098, 256667.54793650145, 257026.0342857108, 252393.8423015832, 251039.21626983624, 249485.0216666634, 248346.37412697868, 250809.20531745537, 252567.28476189982, 250089.9854761864, 251797.08444444236, 253473.55404761495, 254723.7643650756, 253483.43460317192, 251644.44801586994, 259057.4840476177, 254493.00436507608, 254528.1411111077, 253979.282301583, 250721.76682539246, 249543.82563491492, 253478.3828571392, 250507.51333332647, 250713.57087301003, 248182.01698412458, 252753.74896824907]}

fig, ax = plt.subplots(2, 1, figsize=(10, 14))
today = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

i=0
for k,v in dicqq.items():
    ax[i].set_title(f"{k} curve of training for s1-5-cont -T:{today}")
    ax[i].set_xlabel('epsiodes')
    ax[i].plot(v, label=k)
    smthdata = smooth(v)
    ax[i].plot(smthdata,label='Smooth_rewards')
    ax[i].legend()

    i+=1
plt.show()